package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.EnvironmentHistory;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/25
 *
 * 塔吊详情历史数据适配器
 */

public class EnvironmentDataHistoryListAdapter extends RecyclerAdapter<EnvironmentHistory, EnvironmentDataHistoryListAdapter.EnvironmentHistoryListViewHolder> {

    public EnvironmentDataHistoryListAdapter(Context context, List<EnvironmentHistory> dataList) {
        super(context, dataList);
    }

    @Override
    public EnvironmentHistoryListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_environment_data_list_history, null);
        return new EnvironmentHistoryListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(EnvironmentHistoryListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class EnvironmentHistoryListViewHolder extends RecyclerAdapter.BaseViewHolder<EnvironmentHistory>{
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;
        @BindView(R.id.environment_warning_type_tv)
        HXTextView environmentWarningTypeTv;
        @BindView(R.id.environment_alarm_type_tv)
        HXTextView environmentAlarmTypeTv;
        @BindView(R.id.environment_normal_type_tv)
        HXTextView environmentNormalTypeTv;

        public EnvironmentHistoryListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final EnvironmentHistory environmentHistory = dataList.get(position);
            createTimeTv.setText(environmentHistory.getTime());
            if(environmentHistory.getWarnStatus() == 1){//	是否预警，0否，1是
                environmentWarningTypeTv.setVisibility(View.VISIBLE);
                if(environmentNormalTypeTv.getVisibility() == View.VISIBLE){
                    environmentNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                environmentWarningTypeTv.setVisibility(View.GONE);
            }
            if(environmentHistory.getAlarmStatus() == 1){//	是否报警，0否，1是
                environmentAlarmTypeTv.setVisibility(View.VISIBLE);
                if(environmentNormalTypeTv.getVisibility() == View.VISIBLE){
                    environmentNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                environmentAlarmTypeTv.setVisibility(View.GONE);
            }
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(environmentHistory);
                }
            });
        }
    }
}
